import 'package:get/get.dart';
import '../../../entity/daily_events_models.dart';

/// 今日事件状态
class DailyEventsState {
  /// 已选择的标签
  RxList<String> selectedTags = <String>[].obs;

  /// 自定义事件文本
  RxString customEventText = ''.obs;

  /// 是否正在加载
  RxBool isLoading = false.obs;

  /// 今日日期
  RxString todayDate = ''.obs;

  /// 事件列表
  RxList<DailyEvent> events = <DailyEvent>[].obs;

  /// 标签数据
  RxList<TagGroup> tagGroups = <TagGroup>[].obs;

  /// 各部分的事件数据
  RxList<String> dailyCheckInEvents = <String>[].obs;
  RxList<String> entertainmentEvents = <String>[].obs;
  RxList<String> symptomsEvents = <String>[].obs;

  /// 最大显示数量
  static const int maxDisplayCount = 3;
  
  /// 最大记录数量
  static const int maxRecordCount = 10;

  DailyEventsState() {
    // 初始化今日日期
    final now = DateTime.now();
    todayDate.value = '${now.year}年${now.month.toString().padLeft(2, '0')}月${now.day.toString().padLeft(2, '0')}日';
    
    // 初始化测试数据
    _initializeTestData();
  }

  /// 初始化测试数据
  void _initializeTestData() {
    dailyCheckInEvents.value = ['喝水', '洗手', '站立', '晒太阳'];
    entertainmentEvents.value = ['电影', '追剧', '音乐', '电子游戏', '阅读', '运动'];
    symptomsEvents.value = ['疼痛', '感冒', '胃肠道', '皮肤问题', '头痛', '疲劳'];
  }
}

/// 每日事件模型
class DailyEvent {
  final String id;
  final String title;
  final String content;
  final List<String> tags;
  final DateTime createdAt;
  final int? aiScore;
  final String? aiComment;

  DailyEvent({
    required this.id,
    required this.title,
    required this.content,
    required this.tags,
    required this.createdAt,
    this.aiScore,
    this.aiComment,
  });

  factory DailyEvent.fromJson(Map<String, dynamic> json) {
    return DailyEvent(
      id: json['id'] ?? '',
      title: json['title'] ?? '',
      content: json['content'] ?? '',
      tags: List<String>.from(json['tags'] ?? []),
      createdAt: DateTime.parse(json['createdAt'] ?? DateTime.now().toIso8601String()),
      aiScore: json['aiScore'],
      aiComment: json['aiComment'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'title': title,
      'content': content,
      'tags': tags,
      'createdAt': createdAt.toIso8601String(),
      'aiScore': aiScore,
      'aiComment': aiComment,
    };
  }
}
